let city = "杭州";
let region = "杭州";
//getweather(city, region);
getweather("浙江","杭州") ;

const month = [
    "Jan", "Feb", "Mar", "Apr",
    "May", "June", "July", "Aug",
    "Sep", "Oct", "Nov", "Dec"]
function date() {
    var d = new Date();
    document.getElementById("date").innerHTML = d.getDate() + " / " + month[d.getMonth()] + " / " + d.getFullYear();
}

function personal_inf() {
    window.location.href = "个人信息/demo.html";
}

function photo_album() {
    window.location.href = "相册/photo_album.html";
}

function informal_essays() {
    window.location.href = "随笔/informal_essays.html";
}

function other_links() {
    window.location.href = "其他链接/other_links.html";
}

async function getweather(city, region) {
    try {
        const key = "dc90185b75584908b01fb7d2692b0677";
        const CITY_URL = "https://geoapi.qweather.com/v2/city/lookup?";
        const WEATHER_NOW = "https://devapi.qweather.com/v7/weather/now?";


        let res = await fetch(`${CITY_URL}location=${region}&adm=${city}&key=${key}`);
        let resJSON = await res.json();
        //console.log(resJSON);

        let cityID = resJSON.location[0].id;

        //地区
        let _position = resJSON.location[0].name;

        resJSON = await (
            await fetch(`${WEATHER_NOW}location=${cityID}&key=${key}`)
        ).json();
        // console.log(resJSON);

        //天气
        let { temp, text, icon } = resJSON.now;

        let result = _position + "  " + temp + '℃' + " " + text + "  ";

        document.getElementById('weather_fore').innerHTML = result;

        //图标

        var w_img = document.createElement('img');
        w_img.src = `icons/${icon}.svg`;
        w_img.style.width = "5vw" ;
        document.getElementById('weather_fore').appendChild(w_img);


    }
    catch (err) {
        console.log('error!');
    }
}

function hello() {
    window.open ("问卷/questionnaire.html");
    document.getElementById("dialog").hidden = true ;
}